    /*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package mnstudent.dataacesslayer;

import mnstudent.datatranferobject.PriorityObjectDTO;
import java.sql.ResultSet;


/**
 *
 * @author 11520_000
 */
public class PriorityObjectDAL {
    
    //<editor-fold defaultstate="collapsed" desc="Attributes">
    private PriorityObjectDTO m_PriorityObj;
    private DataExecuteUseStoreProcedure m_DataExecute;
    private String  m_sqlCmd;
    
    //</editor-fold>

    public PriorityObjectDAL() {
        this.m_PriorityObj = new PriorityObjectDTO();
        this.m_DataExecute = new DataExecuteUseStoreProcedure();    
        this.m_sqlCmd = "";
    }

    /**
     * Ham lay tat ca cac Doi tuong
     *
     * @return boolean
     */
    public ResultSet getAllPriorityObject() {
       try
        {
            m_sqlCmd = "{Call GetAllPriorityObjectFromDatabase}";
            ResultSet _rsData = this.m_DataExecute.getDataFromDatabase(m_sqlCmd,null);
            return _rsData;
        }catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return null;
    }
     /**
     * Ham lay khoa theo ma khoa
     * @param _id
     * @return tra ve table chon
     */
    public ResultSet getPriorityObjectById(String _id)
    {
        try {
            m_sqlCmd = "{Call GetPriorityObjectByIdFromDatabase(?)}";
            String[] arrId = {_id};
            return this.m_DataExecute.getDataFromDatabase(m_sqlCmd, arrId);
        }
        catch(Exception ex)
        {
            ex.printStackTrace();
        }
        return null;
    }
    
     /**
     * ham them moi khoa xuong database
     * @param _priorityObj
     * @return true: success, false: fail
     */
    public boolean insertPriorityObjectToDatabase(PriorityObjectDTO _priorityObj)
    {
       try {
           m_sqlCmd = "{Call InsertPriorityObjectToDatabase(?,?,?)}";
           String[] arrStr = {_priorityObj.getPriorityObjectID(), _priorityObj.getNameOfObject(), String.valueOf(_priorityObj.getRate())};

           return this.m_DataExecute.updateDataToDatabase(m_sqlCmd,arrStr)>0;
           
       } catch (Exception ex) {
          ex.printStackTrace();
       }
        return false;
    }
    
    /**
     * Ham cap nhat sua doi thong tin khoa
     * @param _major
     * @return tue: thanh cong, false: that bai
     */
    public boolean updatePriorityObjectToDatabase(PriorityObjectDTO _priorityObj)
    {
       try {
           m_sqlCmd = "{Call UpdatePriorityObjectToDatabase(?,?,?)}";
             Object[] arrStr = {_priorityObj.getPriorityObjectID(), _priorityObj.getNameOfObject(), _priorityObj.getRate()};

           return this.m_DataExecute.updateDataToDatabase(m_sqlCmd,arrStr)>0;
           
       } catch (Exception ex) {
          ex.printStackTrace();
       }
        return false;
    }
    
    /**
     * Ham xoa mot khoa ra khoi database
     * @param _major
     * @return 
     */
     public boolean deletePriorityObjectFromDatabase(PriorityObjectDTO _priorityObj)
    {
        try {
           m_sqlCmd = "{Call DeletePriorityObjectFromDatabase(?)}";
           String[] arrStr = {_priorityObj.getPriorityObjectID()};

           return this.m_DataExecute.updateDataToDatabase(m_sqlCmd,arrStr)>0;
           
       } catch (Exception ex) {
          ex.printStackTrace();
       }
        return false;
    }
    //</editor-fold>
}
